package com.utils.export;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.google.common.collect.Lists;
import com.utils.dateUtil.DateUtil;
import com.wf.course.model.goods.GoodsOrderRelation;


public class GoodsSalesExcelExporter {

    /**
     * 类名称：GoodsOrderExcelExporter
     * 类描述：实现商品订单信息表导出功能
     *
     * @version 1.0.0
     */
    public void exportExcel(HttpServletResponse response, List<GoodsOrderRelation> gorList) {

        // 定义导出的Excel文件名称
        String fileName = "销售额统计信息表" + DateUtil.getDateString(new SimpleDateFormat("yyyyMMddHHmmss"));
        //数据处理

        //表头list
        List<String> headerList = Lists.newArrayList();
        headerList.add("序号");
        headerList.add("商品编号");
        headerList.add("商品名称");
        headerList.add("商品分类");
        headerList.add("二级分类");
        headerList.add("授课老师");
        headerList.add("销售量");
        headerList.add("原铜钱消耗");
        headerList.add("新铜钱消耗");
        headerList.add("销售额");
//			headerList.add("总运费");
        headerList.add("实际收入");

        //数据集合
        List<List<String>> dataList = Lists.newArrayList();
        //序号
        int colNum = 0;
        //遍历数据
        for (GoodsOrderRelation gor : gorList) {
            colNum++;
            Object value;

            //每一行的数据list
            List<String> dataRowList = Lists.newArrayList();
            //序号
            dataRowList.add(String.valueOf(colNum));
            //商品编号
            value = gor.getGoodsId();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //商品名称
            value = gor.getGoodsName();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //商品分类:1.课程 2.章节3.vip卡4商品
            value = gor.getGoodsSort();
            value = value == null ? "" : value;

            if ("1".equals(String.valueOf(value))) {
                dataRowList.add("课程");
            } else if ("2".equals(String.valueOf(value))) {
                dataRowList.add("章节");
            } else if ("3".equals(String.valueOf(value))) {
                dataRowList.add("vip卡");
            } else if ("4".equals(String.valueOf(value))) {
                dataRowList.add("商品");
            }

            //二级分类
            value = gor.getCcname();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //授课老师
            value = gor.getSpeakerName();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //商品销量
            value = gor.getGoodsCount();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //原铜钱消耗
            value = gor.getOldCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));


            //新铜钱消耗
            value = gor.getNewCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));
            //销售额
            value = gor.getSaleNum();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //实际支付
            value = gor.getRealIncome();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));


            dataList.add(dataRowList);

        }
        //最后一行的数据list
        List<String> lastRowList = Lists.newArrayList();

        lastRowList.add("总运费");

        lastRowList.add("");
        lastRowList.add("");
        lastRowList.add("");
        lastRowList.add("");
        if (gorList != null && gorList.size() > 0) {
            lastRowList.add(gorList.get(0).getFreight().toString());
        } else {
            lastRowList.add("");
        }
        dataList.add(lastRowList);

        //导出数据
        ExportExcel.doExportExcel(response, fileName, headerList, dataList);
    }

    /**
     * 类名称：GoodsOrderExcelExporter
     * 类描述：实现商品订单信息表导出功能
     *
     * @version 1.0.0
     */
    public void newExportExcel(HttpServletResponse response, List<GoodsOrderRelation> list) {

        String fileName = "销售额统计信息表" + DateUtil.getDateString(new SimpleDateFormat("yyyyMMddHHmmss"));

        List<String> headerList = Lists.newArrayList();
        headerList.add("序号");
        headerList.add("商品编号");
        headerList.add("商品名称");
        headerList.add("所属课程名称");
        headerList.add("商品分类");
        headerList.add("二级分类");
        headerList.add("授课老师");
        headerList.add("销售量");
        headerList.add("原铜钱消耗");
        headerList.add("新铜钱消耗");
        headerList.add("金币");
        headerList.add("新金币");
        headerList.add("销售额");
        headerList.add("实际收入");

        //数据集合
        List<List<String>> dataList = new ArrayList<>();
        //序号
        int num = 0;
        //遍历数据
        for (GoodsOrderRelation gor : list) {
            num++;
            Object value;
            //每一行的数据list
            List<String> dataRowList = new ArrayList<>();

            dataRowList.add(String.valueOf(num));

            // 商品编号
            value = gor.getGoodsId();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 商品名称
            value = gor.getGoodsName();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 所属课程名称
            value = gor.getCourseName();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 商品分类
            value = gor.getGoodsSort();
            value = value == null ? "" : value;

            if ("1".equals(String.valueOf(value))) {
                dataRowList.add("课程");
            } else if ("2".equals(String.valueOf(value))) {
                dataRowList.add("章节");
            } else if ("3".equals(String.valueOf(value))) {
                dataRowList.add("课程包");
            }

            //二级分类
            value = gor.getCcname();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //授课老师
            value = gor.getSpeakerName();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //商品销量
            value = gor.getGoodsCount();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //原铜钱消耗
            value = gor.getOldCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //新铜钱消耗
            value = gor.getNewCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //金币
            value = gor.getGold();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //新金币
            value = gor.getNewGold();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //销售额
            value = gor.getSaleNum();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            //实际支付
            value = gor.getRealIncome();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            dataList.add(dataRowList);

        }
        ExportExcel.doExportExcel(response, fileName, headerList, dataList);
    }

    /**
     * 类名称：exportPurchaseAmountExcel
     * 类描述：用户购买金额导出excel
     *
     * @version 1.0.0
     */
    public void exportPurchaseAmountExcel(HttpServletResponse response, List<GoodsOrderRelation> list) {

        String fileName = "用户购买金额统计信息表" + DateUtil.getDateString(new SimpleDateFormat("yyyyMMddHHmmss"));

        List<String> headerList = Lists.newArrayList();
        headerList.add("序号");
        headerList.add("手机号");
        headerList.add("渠道");
        headerList.add("原铜钱消耗");
        headerList.add("新铜钱消耗");
        headerList.add("金币");
        headerList.add("新金币");
        headerList.add("微信支付");
        //数据集合
        List<List<String>> dataList = new ArrayList<>();
        //序号
        int num = 0;
        //遍历数据
        for (GoodsOrderRelation gor : list) {
            num++;
            Object value;
            //每一行的数据list
            List<String> dataRowList = new ArrayList<>();

            dataRowList.add(String.valueOf(num));

            // 手机号
            value = gor.getTelephone();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 渠道
            value = gor.getUserSource();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 老铜钱
            value = gor.getOldCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 新铜钱
            value = gor.getNewCopperCash();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 金币
            value = gor.getGold();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 新金币
            value = gor.getNewGold();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            // 微信支付
            value = gor.getRealPay();
            value = value == null ? "" : value;
            dataRowList.add(String.valueOf(value));

            dataList.add(dataRowList);
        }
        ExportExcel.doExportExcel(response, fileName, headerList, dataList);
    }
}
